package cn.sangedon.review.data.controller;

import cn.sangedon.review.common.service.data.SpiderMateDataService;
import cn.sangedon.review.common.service.data.SpiderService;
import cn.sangedon.review.common.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "爬虫")
@RestController
@RequestMapping("spider")
public class SpiderController {
    @Autowired
    private SpiderMateDataService spiderMateDataService;

    @Autowired
    private SpiderService spiderService;

    @ApiOperation("执行爬虫")
    @GetMapping("exec/{id}")
    public Result execSpider(@PathVariable Long id) {
        spiderMateDataService.execSpider(id);
        return Result.ok();
    }

    @ApiOperation("查询可用爬虫列表")
    @GetMapping("list")
    public Result listSpider() {
        return Result.okBuilder().data(spiderService.listSpiderMateData()).build();
    }

    /**
     * @param type 1：涨停;2：跌停
     * @param crawDate 爬取涨跌停数据日期,格式：{yyyyMMdd},如20220928
     * @return
     */
    @ApiOperation("爬取东方财富某日涨跌停数据")
    @GetMapping("limit/data/{type}/{crawDate}")
    public Result crawLimitData(@PathVariable Integer type, @PathVariable String crawDate) {
        spiderService.crawLimitData(type, crawDate);
        return Result.ok();
    }

    /**
     * 爬取雪球实时交易数据
     *
     * @return
     */
    @ApiOperation("爬取雪球实时交易数据")
    @GetMapping("craw/snowball")
    public Result crawSnowball() {
        spiderService.crawSnowball();
        return Result.ok();
    }
}
